//
//  LSFoundationViewController.swift
//  EasySwift
//
//  Created by 王隆帅 on 2017/6/7.
//  Copyright © 2017年 王隆帅. All rights reserved.
//

import UIKit

class LSFoundationViewController: UIViewController , UITableViewDelegate, UITableViewDataSource {

    var tableView: UITableView?;
    
    lazy var dataArray: NSMutableArray = {
        
        let mutArray: NSMutableArray = ["NSNotification","Lock","Runtime"];
        
        return mutArray;
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.cyan;
        
        self.tableView = UITableView.init(frame: self.view.bounds, style: UITableViewStyle.plain)
        self.tableView?.delegate = self as UITableViewDelegate;
        self.tableView?.dataSource = self as UITableViewDataSource;
        self.tableView?.separatorStyle = UITableViewCellSeparatorStyle.none;
        self.tableView?.backgroundColor = UIColor.blue;
        
        self.view.addSubview(self.tableView!);

    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return self.dataArray.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cellStr = "tableViewCellStr";
        var cell: UITableViewCell?;
        
        cell = tableView.dequeueReusableCell(withIdentifier: cellStr);
        
        if cell == nil {
            
            cell = UITableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: cellStr);
            cell?.backgroundColor = UIColor.yellow;
        }
        
        cell?.textLabel?.text = self.dataArray[indexPath.row] as? String;
        
        return cell!;
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return 50;
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        if indexPath.row == 0 {
            
            let vc = NSNotificationTest();
            self.navigationController?.pushViewController(vc, animated: true);
        }
        
        if indexPath.row == 1 {
            
            let vc = LockTest();
            self.navigationController?.pushViewController(vc, animated: true);
        }
        
        if indexPath.row == 2 {
            
            let vc = RuntimeTest();
            self.navigationController?.pushViewController(vc, animated: true);
        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
